package com.HW;

/**
 * @ClassName : TJumpHome
 * @Author : kele
 * @Date: 2023/10/31 20:30
 * @Description :
 */
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class TJumpHome {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();

        int[] arr = Arrays.stream(str.substring(1, str.length() - 1).split(",")).mapToInt(Integer::parseInt).toArray();
        int cnt = Integer.parseInt(sc.nextLine());

        handle(arr,cnt);


    }

    public static void handle(int[] arr,int cnt){

        HashMap<Integer, Integer> map = new HashMap<>();

        int lindex = 0;

        int sum = Integer.MAX_VALUE;
        for (int i = 0; i < arr.length; i++) {

            int num = cnt - arr[i];

            if(map.keySet().contains(num)){
                if(sum > map.get(num) + i){
                    lindex = i;
                    sum = map.get(num) + i;
                }
            }else{
                map.putIfAbsent(arr[i],i);
            }
        }

        System.out.println("["+arr[sum-lindex]+","+arr[lindex]+"]");



    }
}
